layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'ax', 'func', 'tree', 'util'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ZTree = layui.ztree;
    var $ax = layui.ax;
    var laydate = layui.laydate;
    var admin = layui.admin;
    var func = layui.func;
    var tree = layui.tree;
    var util = layui.util;

    form.render('select')

    /**
     * 系统管理--消息管理
     */
    var base = {
        tableId: "baseTable"    //表格id
    };

    //渲染时间选择框
    laydate.render({
        elem: '#timeLimit',
        range: true,
        max: Feng.currentDate()
    });

    /**
     * 初始化表格的列
     */
    base.initColumn = function () {
        return [[
            {type: 'checkbox', totalRowText: '合计'},
            {field: 'company_name', align: "center", sort: true, title: '公司名称'},
            {field: 'user_name', align: "center", sort: true, title: '用户名称'},
            {field: 'logon_id', align: "center", sort: true, title: '手机号码'},
            {field: 'order_id', align: "center", sort: true, title: '订单编号'},
            {field: 'order_content', align: "center", sort: true, title: '订单内容'},
            {field: 'order_status_name', align: "center", sort: true, title: '订单状态'},
            {field: 'created_at', align: "center", sort: true, title: '创建时间'},
            {field: 'updated_at', align: "center", sort: true, title: '付费时间'},
            {field: 'order_amount', align: "center", sort: true, title: '付费金额', totalRow: true}
        ]];
    };


    /**
     * 点击查询按钮
     */
    base.search = function () {
        var queryData = {};
        queryData['keyword'] = $("#keyword").val();
        queryData['timeLimit'] = $("#timeLimit").val();
        queryData['type'] = $("#orderType").find("option:selected").val();
        queryData['status'] = $("#status").find("option:selected").val();
        table.reload(base.tableId, {
            where: queryData, page: {curr: 1}
        });
    };

    // 渲染表格
    var tableResult = table.render({
        title: "付费列表",
        elem: '#' + base.tableId,
        url: Feng.ctxPath + '/order/list',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        cols: base.initColumn(),
        totalRow: true
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        base.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        base.exportExcel();
    });

    base.exportExcel = function () {
        var checkRows = table.checkStatus(base.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };
});

